package service

import (
	"ksd-social-api/modules/note/model"
	"ksd-social-api/modules/note/model/context"
	"ksd-social-api/modules/note/model/vo"
	"ksd-social-api/utils"
	"strconv"
	"time"
)

type AdminNoteCategoryService struct{}

/**
 * @author feige
 * @date 2023-10-10
 * @version 1.0
 * @desc  查询所有的发布的和未删除的小册分类信息
 */
func (service *AdminNoteCategoryService) FindCategoriesAll(status int64, channelId, systemId uint64) ([]*vo.NoteCategoryDetailVo, error) {
	var noteVos []*vo.NoteCategoryDetailVo
	categoryList, _ := adminNoteCategoryMapper.FindCategoriesAllAdmin(status, channelId, systemId)
	for _, category := range categoryList {
		noteVo := vo.NoteCategoryDetailVo{}
		utils.CopyProperties(&noteVo, category)
		noteVos = append(noteVos, &noteVo)
	}
	return noteVos, nil
}

/**
 * @author feige
 * @date 2023-10-10
 * @version 1.0
 * @desc  根据id删除
 */
func (service *AdminNoteCategoryService) DelById(id uint64, systemId uint64) bool {
	return adminNoteCategoryMapper.DelById(id, systemId)
}

/**
 * @author feige
 * @date 2023-10-10
 * @version 1.0
 * @desc  修改状态
 */
func (service *AdminNoteCategoryService) UpdateFieldById(ctx context.NoteUpdateContext) bool {
	return adminNoteCategoryMapper.UpdateFieldById(ctx.Id.Uint64(), ctx.Field, ctx.Value, ctx.SystemId)
}

/*
*
保存分类
*/
func (service *AdminNoteCategoryService) SaveUpdateNoteCategory(ctx context.NoteCategoryContext) bool {
	// 保存入库
	var noteCategory model.NoteCategory
	utils.CopyProperties(&noteCategory, ctx)
	parseUint, _ := strconv.ParseUint(ctx.Id, 10, 64)
	noteCategory.Id = parseUint
	adminNoteCategoryMapper.SaveUpdateCategory(noteCategory)
	return true
}

/*
*
保存分类
*/
func (service *AdminNoteCategoryService) CopyData(id uint64, systemId uint64) bool {
	// 保存入库
	data := adminNoteCategoryMapper.GetById(id, systemId)
	data.Id = 0
	data.Status = 0
	data.CreateTime = time.Now()
	data.UpdateTime = time.Now()
	adminNoteCategoryMapper.SaveUpdateCategory(*data)
	return true
}
